import { defineStore } from "pinia";
import { ref,reactive } from 'vue';
export const useKeepAlive = defineStore("keepAlive",()=>{
  const caches = reactive(["主页"])
  const dynamicTags = reactive([
    {type:"success",path:"/",name: "主页"}
  ])
  const AddTags = (to)=>{
    to.type = "success"
    dynamicTags.push(to);
  }
  const toTag = (currRouter)=>{
    dynamicTags.forEach(item=>{
      if(item.name === currRouter.name){
        item.type = "success"
      }else{
        item.type = "info"
      }
    })
  }
  const removeCachesByName = (name)=>{
    for (let index = 0; index < caches.length; index++) {
      if(caches[index] === name){
        caches.splice(index,1)
        return
      }
    }
  }
  return {caches,dynamicTags,AddTags,toTag,removeCachesByName}
})